import 'package:flutter/material.dart';
import 'package:shortmovieapp/Common.dart';
import 'package:shortmovieapp/data/viewData.dart';
import 'package:shortmovieapp/myPages/shareView.dart';

class mePage extends StatefulWidget {
  const mePage({super.key});

  @override
  State<mePage> createState() => _mePageState();
}

class _mePageState extends State<mePage> {
  @override
  Widget build(BuildContext context) {
    return Container(padding:const EdgeInsets.fromLTRB(10, 30, 10, 0),
    child: Scaffold(
      appBar:PreferredSize(preferredSize:const Size.fromHeight(40), child:  
      AppBar(
        backgroundColor:Colors.transparent,
        actions: [
          IconButton(onPressed: ()=>onClickScan(context), icon: const Icon(Icons.adf_scanner,size: 20,)),
          IconButton(onPressed: ()=>onClickSetting(context), icon: const Icon(Icons.settings,size: 20))
        ],
      )),
      body: Column(children: [
        const SizedBox(height: 10,),
        Container(width:double.maxFinite,alignment: Alignment.centerLeft,
          child:const Text("欢迎来到鸭鸭短剧",style: TextStyle(fontSize: 18),),)
        ,const SizedBox(height: 20,)
        ,Row(children:[Container(alignment: Alignment.centerLeft,width: 80,height:30,
                  child: ElevatedButton(style:ButtonStyle( backgroundColor:  MaterialStateProperty.all<Color>(Colors.orange))
          ,onPressed: ()=>onClickLogin(context)
          , child: const Text("登录",style: TextStyle(color: Colors.white),)),
         )
          ])
        ,const SizedBox(height: 20,)
        ,Container(
          padding: const EdgeInsets.fromLTRB(10,20,10,20),
          decoration: BoxDecoration(borderRadius: BorderRadius.circular(4),color:Colors.white10,),
          alignment: Alignment.center,
          child:
          // GridView.extent(maxCrossAxisExtent: 100,
          //   mainAxisSpacing: 10,childAspectRatio: 1.0,children: [
          //   IconTextButton(onClick: onClickHistory,title:"浏览历史")
          //               ,IconTextButton(onClick: onClickMyLike,title:"我的点赞")
          //               ,IconTextButton(onClick: onClickSystemMessage,title:"系统消息")
          //               ,IconTextButton(onClick: onClickStore,title:"商店")
          // ],) 
           Row(
            mainAxisAlignment: MainAxisAlignment.spaceAround,
              children: [IconTextButton(size:20,icon:Icons.history,onClick: ()=>onClickHistory(context),title:"浏览历史")
                        ,IconTextButton(size:20,icon:Icons.heart_broken,onClick: ()=>onClickMyLike(context),title:"我的点赞")
                        ,IconTextButton(size:20,icon:Icons.message,onClick: ()=>onClickSystemMessage(context),title:"系统消息")
                        ,IconTextButton(size:20,icon:Icons.store_mall_directory,onClick: ()=>onClickStore(context),title:"商店")
                        ])
          ,)
        ,const SizedBox(height: 10,), 
        Container(
          padding: const EdgeInsets.fromLTRB(10,20,10,20),
          decoration: BoxDecoration(borderRadius: BorderRadius.circular(4),color:Colors.white10),
          alignment: Alignment.center,
          child:   
           Wrap(
            spacing: 25,
            runSpacing: 10,
            alignment: WrapAlignment.spaceAround,
              children: [IconTextButton(size:25,icon:Icons.room_preferences,onClick: ()=>onClickPreference(context),title:"看剧偏好")
                        ,IconTextButton(size:25,icon:Icons.upload,onClick: ()=>onClickUpload(context),title:"上传视频")
                        ,IconTextButton(size:25,icon:Icons.help,onClick: ()=>onClickHelp(context),title:"反馈与帮助")
                        ])
          ,),
      ]),
    )
    );
  }

  void onClickScan(BuildContext context) {
    Debug.log("click scan");
    showSimpleDialog(context, "功能正在努力开发中...");

  }

  void onClickSetting(BuildContext context) {
    Debug.log("click setting");
    showSimpleDialog(context, "功能正在努力开发中...");
  }
  void onClickLogin(BuildContext context){
    Debug.log("click login");
    showSimpleDialog(context, "功能正在努力开发中...");
  }
  void onClickHistory(BuildContext context){
    Debug.log("click history");
    //showSimpleDialog(context, "功能正在努力开发中...");

    showMyDialog(context, "敬请期待", "功能正在努力开发中...", () => {Debug.log("关闭History弹窗")});
  }
   void onClickMyLike(BuildContext context){
    Debug.log("click my like");
    showMyDialog(context, "敬请期待", "功能正在努力开发中...", () => {Debug.log("关闭MyLike弹窗")});
  }
   void onClickSystemMessage(BuildContext context){
    Debug.log("click system message");
    showMyDialog(context, "敬请期待", "功能正在努力开发中...", () => {Debug.log("关闭SystemMessage弹窗")});
  }
   void onClickStore(BuildContext context){
    Debug.log("click store");
    showMyDialog(context, "敬请期待", "功能正在努力开发中...", () => {Debug.log("关闭Store弹窗")});
  }
  void onClickPreference(BuildContext context){
    Debug.log("click preference");
    showMyDialog(context, "敬请期待", "功能正在努力开发中...", () => {Debug.log("关闭preference弹窗")});
  } 
  void onClickUpload(BuildContext context){
    Debug.log("click upload");
    Navigator.of(context).pushNamed(MyPageRoute.createMovie);
  }  
   void onClickHelp(BuildContext context){
    Debug.log("click help");
    showMyDialog(context, "敬请期待", "功能正在努力开发中...", () => {Debug.log("关闭help弹窗")});
  }  

}

class IconTextButton extends StatelessWidget {
  final Function()? onClick;
  final String title;
  final double size;
  final IconData icon;
  const IconTextButton({super.key,this.title = "",this.onClick,this.size = 20,required this.icon});

  @override
  Widget build(BuildContext context) {
    var transparentColor =  MaterialStateProperty.all<Color>(Colors.transparent);
    return TextButton(
      style: ButtonStyle(backgroundColor:transparentColor,
                         overlayColor:transparentColor,
      iconSize: MaterialStatePropertyAll(size)),
    onPressed: onClick,
    child: Column(children: [
      Icon(icon, color: Colors.white,),
      const SizedBox(height: 5,),
      Text(title,style: TextStyle(fontSize: size /2.0,color: Colors.white),)],
    ),
    );
  }
}